home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / mflms101.arc / PIPER.C < prev    next >
C/C++ Source or Header  |  1989-11-25  |  3KB  |  97 lines

  1. /************************************************************************/
  2. /*                                                                      */
  3. /*  PIPER - filename piper                                              */
  4. /*                                                                      */
  5. /*  Outputs a list of fully-qualified filenames matching the input      */
  6. /*  specification.                                                      */
  7. /*                                                                      */
  8. /*  Copyright 1989 by Robert B. Stout dba MicroFirm                     */
  9. /*  All rights reserved                                                 */
  10. /*                                                                      */
  11. /************************************************************************/
  12.  
  13. #include <stdio.h>
  14. #include <string.h>
  15. #include <ctype.h>
  16. #include <dos.h>
  17. #include <mflfiles.h>
  18.  
  19. #define _A_ANY 0xff
  20.  
  21. LOGICAL recurse = FALSE;
  22.  
  23. void pipem(char *spec)
  24. {
  25.         char path[MAX_FLEN], dummy[13], fname[MAX_FLEN], file[MAX_FLEN];
  26.         struct find_t ffblk;
  27.  
  28.         fnsplit(spec, NULL, path, NULL, dummy, NULL, NULL);
  29.  
  30.         /* First print all filenames except `dot' directories           */
  31.  
  32.         if (SUCCESS == _dos_findfirst(spec, _A_ANY, &ffblk)) do
  33.         {
  34.                 if ('.' == ffblk.name[0])
  35.                         continue;
  36.                 if (path)
  37.                         strcat(strcpy(fname, path), ffblk.name);
  38.                 else    strcat(strcpy(fname, ffblk.name), "\\");
  39.                 flnorm(fname, file);
  40.                 if (file)
  41.                         puts(file);
  42.  
  43.                 /* If this was a directory, process it if /R selected   */
  44.  
  45.                 if (!recurse || !(ffblk.attrib & _A_SUBDIR))
  46.                         continue;
  47.                 if (path)
  48.                         strcat(strcpy(fname, path), ffblk.name);
  49.                 else    strcpy(fname, ffblk.name);
  50.                 strcat(fname, "\\*.*");
  51.                 pipem(fname);
  52.         } while (SUCCESS == _dos_findnext(&ffblk));
  53. }
  54.  
  55. void blow_off(int ercode)
  56. {
  57.         if (ercode)
  58.                 putchar('\a');
  59.         puts("Usage: PIPER [/h] [/r] [d:][path]");
  60.         puts("options: /h - Help");
  61.         puts("         /r - Recursively process subdirectories");
  62.         exit(ercode);
  63. }
  64.  
  65. main(int argc, char *argv[])
  66. {
  67.         int n, argn = 0;
  68.         char fname[MAX_FLEN];
  69.  
  70.         for (n = 1; n < argc; ++n)
  71.         {
  72.                 if ('/' == argv[n][0])
  73.                 {
  74.                         switch (tolower(argv[n][1]))
  75.                         {
  76.                         case ('r'):
  77.                                 recurse = TRUE;
  78.                                 break;
  79.                         case ('h'):
  80.                                 blow_off(0);
  81.                         default:
  82.                                 blow_off(ERROR);
  83.                         }
  84.                 }
  85.                 else if (!argn)
  86.                         argn = n;
  87.                 else    blow_off(ERROR);
  88.         }
  89.         if (!argn)
  90.                 pipem("*.*");
  91.         else
  92.         {
  93.                 strcat(strcpy(fname, argv[argn]), "\\*.*");
  94.                 pipem(fname);
  95.         }
  96. }
  97.